package club.ximeng.javafxstart;

import club.ximeng.javafxstart.config.AppConfig;
import cn.hutool.core.io.resource.ResourceUtil;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;

/**
 * @author liu xm
 * @date 2022-02-12 12:47
 */
@Slf4j
public class App extends Application {
    @Override
    public void start(Stage stage) throws IOException {
        log.info("start");
        // 加载并创建主场景
        FXMLLoader fxmlLoader = new FXMLLoader(App.class.getResource("view/main-view.fxml"));
        Scene scene = new Scene(fxmlLoader.load(), AppConfig.stageWidth, AppConfig.stageHeight);
        // 设置窗口信息
        stage.setTitle(AppConfig.title);
        stage.setResizable(AppConfig.stageResizable);
        stage.getIcons().add(new Image(ResourceUtil.getStream(AppConfig.icon)));
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        AppConfig.init();
        launch();
    }

    /**
     * 应用程序初始化
     */
    @Override
    public void init() throws Exception {
        log.info("init");
        super.init();
    }

    /**
     * 应用程序停止
     */
    @Override
    public void stop() throws Exception {
        log.info("stop");
        super.stop();
    }
}
